Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cas2v2/cba 130 search by crn #2848

Merged
merged 9 commits into from
Jan 28, 2025
Merged

Conversation

tobybatchmoj
Copy link
Contributor

No description provided.

@tobybatchmoj tobybatchmoj changed the base branch from main to cas2v2/dev January 22, 2025 15:50
@garethCAS2 garethCAS2 marked this pull request as ready for review January 27, 2025 15:28
get:
tags:
- People operations
summary: Searches for a Person by their CRN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you define operationId here you can generate a nicer controller function name .e.g

operationId: searchByCrn

Same goes for other endpoint

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

override fun peopleSearchGet(nomsNumber: String): ResponseEntity<Person> {
val currentUser = nomisUserService.getUserForRequest()
override fun peopleSearchByCrnCrnGet(crn: String): ResponseEntity<Person> {
val deliusUser = cas2v2UserService.getUserForRequest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably we know this is a delius user because of the roles this endpoint is limited to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


val probationOffenderResult = offenderService.getPersonByNomsNumber(nomsNumber, currentUser)
val personInfo = deliusOffenderService.getPersonInfoResult(crn, deliusUser.username, false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll see this is complaining because you should be using this version instead:

fun getPersonInfoResult(
    crn: String,
    limitedAccessStrategy: LimitedAccessStrategy,
  )

To enable this add something like the following to the bottom of OffenderService (this may not compile, hopefully you get the idea!)

fun Cas2v2UserEntity.limitedAccessStrategy() = when(userType) {
   DELIUS ->  LimitedAccessStrategy.ReturnRestrictedIfLimitedAccess(this.username)
   else -> error("Can't provide strategy for users of type $userType")
}

And then use the extension function on the current user to get the strategy e.g.

deliusOffenderService.getPersonInfoResult(crn, deliusUser.limitedAccessStrategy())

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -39,6 +39,51 @@ class OffenderService(

private val log = LoggerFactory.getLogger(this::class.java)

fun getPersonByNomsNumberAndActiveCaseLoadId(nomsNumber: String, activeCaseLoadId: String): ProbationOffenderSearchResult {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this is the same as getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity) but instead of passing a NomisUserEntity (that is deprecated), you instead pass in the actual value from NomisUserEntity that is required (Active Case ID)?

If that's the case, pretty much all of this code is common and can be shared. Could you not delete all of the body of getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity) and just delegate to your new function e.g.

fun getPersonByNomsNumber(nomsNumber: String, currentUser: NomisUserEntity) = getPersonByNomsNumberAndActiveCaseLoadId(nomsNumber, currentUser.activeNomisCaseloadId)

This means that no more unit tests on the service would be required (as they probably are currently)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

@Nested
inner class WhenSuccessfulCRN {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at the outline for this class there's a top level Cas2v2PeopleSearchGet class containing these 4 inner classes. I think that top level one should be renamed to SearchByNomisId and contain the two existing inner classes.

There should then be another top level inner class called SearchByCrn which contains the two new inner classes

e.g.

Cas2v2PersonSearchTest
   SearchByNomisId
      WhenThereIsAnError
      WhenSuccesfull 
   SearchByCrn
      WhenThereIsAnError
      WhenSuccesfull 

We don't tend to have that third level of inner classes else where in the code base and just have success and error tests in one inner class, i guess this is something CAS2 do!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor

@davidatkinsuk davidatkinsuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT, just some suggestions around style/reuse

Base automatically changed from cas2v2/dev to main January 28, 2025 10:07
@garethCAS2 garethCAS2 force-pushed the cas2v2/cba-130-search-by-crn branch from ac451c1 to 31cca81 Compare January 28, 2025 10:41
@tobybatchmoj tobybatchmoj merged commit cce9a8f into main Jan 28, 2025
8 checks passed
@tobybatchmoj tobybatchmoj deleted the cas2v2/cba-130-search-by-crn branch January 28, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants